package com.example.myapplication.activity

import android.os.Bundle
import android.os.Handler
import android.util.Log
import androidx.activity.enableEdgeToEdge
import androidx.appcompat.app.AppCompatActivity
import androidx.core.view.ViewCompat
import androidx.core.view.WindowInsetsCompat
import com.example.myapplication.R
import com.example.myapplication.adapter.SplashViewPagerAdapter
import com.example.myapplication.databinding.ActivitySplashBinding
import com.example.myapplication.utils.JsonUtils
import com.example.myapplication.utils.NetUtils
import okhttp3.FormBody
import okhttp3.Headers

class SplashActivity : AppCompatActivity() {
    lateinit var binding: ActivitySplashBinding
    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        enableEdgeToEdge()
        binding = ActivitySplashBinding.inflate(layoutInflater)
        setContentView(binding.root)
        ViewCompat.setOnApplyWindowInsetsListener(findViewById(R.id.main)) { v, insets ->
            val systemBars = insets.getInsets(WindowInsetsCompat.Type.systemBars())
            v.setPadding(systemBars.left, systemBars.top, systemBars.right, systemBars.bottom)
            insets
        }
        val splashImages = arrayOf(R.drawable.splash01, R.drawable.splash02, R.drawable.splash03)
        binding.viewPager.adapter = SplashViewPagerAdapter(splashImages)
        val requestBody =
            FormBody.Builder().add("userName", "admin").add("password", "admin").build()
//        NetUtils.request("/user/login", requestBody, null, Handler {
//            Log.d("TAG", "onCreate: ${it.obj}")
//            val data = JsonUtils.toObject(it.obj as String)
//            val headers = Headers.Builder()
//            headers.add("token", JsonUtils.getString(data, "token"))
//            NetUtils.request("/weather", null, headers.build(), Handler {
//                Log.d("TAG", "onCreate: ${it.obj}")
//                false
//            })
//            false
//        })
        val sharedPreferences = getSharedPreferences("Chihiro", MODE_PRIVATE)
        sharedPreferences.edit().putString("chihiro", "123").commit()
        sharedPreferences.edit().putString("chihi", "123456").commit()
    }
}